package cn.wolfcode.shop.cloud.redis;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

@Configuration
@EnableConfigurationProperties(RedisProperties.class)
@ConditionalOnProperty(prefix = "redis",name = "host")
public class RedisAutoConfiguration {
    @Bean
    public JedisPool jedispool(RedisProperties redisProperties){
        //jedis连接池配置对象

        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(redisProperties.getPoolMaxTotal());
        config.setMaxIdle(redisProperties.getPoolMaxIdle());
        config.setMaxWaitMillis(redisProperties.getPoolMaxWait());
        return new JedisPool(config,redisProperties.getHost(),
                redisProperties.getPort(),redisProperties.getTimeout(),redisProperties.getPassword());
    }
    @Bean
    public RedisService redisService(){
        return new RedisService();
    }
}